import { timer } from '@/config'
import { Component, Vue } from 'vue-property-decorator'

@Component
export default class TimerMixins extends Vue {
  activeIndex = 0
  timerFn: any = null

  startTimerFn(this: any) {
    this.timerFn = setInterval(() => {
      if (this.activeIndex < this.timerMaxLength - 1) {
        this.activeIndex += 1
      } else {
        this.activeIndex = 0
      }
    }, timer)
  }
  restartTimerFn() {
    this.startTimerFn()
  }

  clearTimerFn() {
    clearInterval(this.timerFn)
    this.timerFn = null
  }

  beforeDestroy() {
    this.clearTimerFn()
  }

  handleMouseOver() {
    this.clearTimerFn()
  }

  handleMouseOut() {
    this.restartTimerFn()
  }
}
